﻿<#include "/macro.include"/>
<#include "/java_copyright.include">
<#assign className = table.className>   
<#assign classNameLower = className?uncap_first> 
<#include "/custom.include"/> 
<#assign actionExtension = "do"> 
/**
 * [${table.tableAlias}] author by $YourName$
 * 
 */
$(function(){
			$('#${className}List').datagrid({
				title:'${table.tableAlias}列表',
				iconCls:'icon-save',
				width :itcmorWindowWidth(),
				height:itcmorWindowHeight(),
				nowrap: false,
				striped: true,
				collapsible:true,
				url:'${classNameLower}_list.action',//datagrid_data.json
				sortName: 'guid',
				sortOrder: 'desc',
				remoteSort: false,
				idField:'guid',
				frozenColumns:[[
	                {field:'ck',checkbox:true},     
	        <#list table.columns as column>
					   <#if column.pk>    
	        		     {field:'${column.columnNameLower}',title:'${column.columnAlias}',width:288}
	        		   </#if>
	        </#list>
				]],
				columns:[[
				  <#list table.columns as column>
					   <#if column.pk>    
	        		   <#else>
	        		       <#if column.isDateTimeColumn>
					          {field:'${column.columnNameLower}',title:'${column.columnAlias}',width:150,format:'Y-m-d'},
					           <#else>
					           {field:'${column.columnNameLower}',title:'${column.columnAlias}',width:150},
					          </#if> 
	        		   </#if>
	        </#list>
	        	{field:'opt',title:'操作',width:100,align:'center', rowspan:2,
						formatter:function(value,rec){
							return '<a onclick=\'toUpdate("<%=basePath%>com/itcmor/web/dayplan/${className}/toUpdate${className}.do?{actionForm.guid}='+rec.roleid+'")\' href="javaScript:void()">编辑</a> ';
						}
					}
				]],
				pagination:true,
				rownumbers:true,
				toolbar:[{
					id:'btnadd',
					text:'增加',
					iconCls:'icon-add',
					handler:function(){
						toInsert();
					}
				},{
					id:'btncut',
					text:'删除',
					iconCls:'icon-cut',
					handler:function(){
					delData();
					}
				},{
					id:'btnedit',
					text:'编辑',
					iconCls:'icon-edit',
					handler:function(){
					toUpdate();
					}
				},{
					id:'btnedit',
					text:'查询',
					iconCls:'icon-search',
					handler:function(){
					info('Search${className}');
					}
				}]
			});
		});
		function toInsert(){
		$('#btnsave').linkbutton('enable');
						$('#${className}Form').form('clear');
						info('${className}');
		}
		function toUpdate(){
						$('#btnedit').linkbutton('enable');
						var guid = getSelected();
						if(guid){
						info('${className}');
						loaddata(guid);
						}
						else{
						   $.messager.alert('操作提示','请选择要编辑的记录！');
						}
		}
		function delData(){
            var guids = getSelections();
            $.messager.confirm('删除确认','删除后数据无法恢复，您确定删除吗?', function(r){
                if(r){
               	    var url = '${classNameLower}_delete.action';
            			$.getJSON(url, {guids: guids}, function(json){
            				 $('#DsystemSurveyList').datagrid('reload');
            			});
                }
            });
		}
		function getSelected(){
			var selected = $('#${className}List').datagrid('getSelected');
			if (selected){
				<#list table.columns as column>
				   <#if column.pk>    
				   return selected.${column.columnNameLower}; 
				   </#if>
     		   </#list>
			}
		}
		function getSelections(){
			var ids = '';
			var rows = $('#${className}List').datagrid('getSelections');
			for(var i=0;i<rows.length;i++){
			<#list table.columns as column>
				   <#if column.pk>    
				   ids = ids +rows[i].${column.columnNameLower}+',';
				   </#if>
     		   </#list>
				
			}
			if(ids == ''){
			}else{
				ids = ids.substring(0, ids.length-1);
			}
			return ids;
		}
		function clearSelections(){
			$('#${className}List').datagrid('clearSelections');
		}
		function info(divid){
			$('#'+divid).window('open');
		}
		function loaddata(guid){
			$('#${className}Form').form('load','${classNameLower}_toUpdate${className}.action?${classNameLower}.<#list table.columns as column><#if column.pk>${column.columnNameLower}</#if></#list>='+guid+'&time='+new Date());
		}
		function ajaxSubmit(){
		    $('#${className}Form').form('submit',{
		     url:'${classNameLower}_saveOrUpdate${className}.action',
		     onSubmit:function(){
		     return $(this).form('validate');
		     },
		     success:function(data){
		     var msg  = eval(data);
		     $('#${className}').dialog('close');
		     $('#${className}List').datagrid('reload');
		     $.messager.alert('操作提示',msg[0].msg);
		     }
		    }); 
		    //$('#${className}Form').submit();
		}
		function reload(){
		var p = $('#${className}List').datagrid('getPager');
		     p.reload();
		}
		function searchData(){
		 var queryParams = { <#list table.notPkColumns as column>${column.columnNameLower}:$('#s_${column.columnNameLower}').val(),</#list>guid:''};      
		 $('#Search${className}').window('close');
		 $('#${className}List').datagrid('load',queryParams);
		}
		


